package com.briup.estore.web.servlet;

import com.briup.estore.common.dto.UserPasswordUpdateDTO;
import com.briup.estore.common.result.Result;
import com.briup.estore.common.utils.JsonUtils;
import com.briup.estore.service.UserService;
import com.briup.estore.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author briup-adam
 * @Date 2023/8/4 下午2:41
 * @Description 用户修改登录密码
 **/
@WebServlet("/user/updatePassword")
public class UserUpdatePasswordServlet extends BaseServlet {
    private UserService userService=new UserServiceImpl();

    @Override
    protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String data = readData(req);
        UserPasswordUpdateDTO userPasswordUpdateDTO = JsonUtils.toObject(data, UserPasswordUpdateDTO.class);
        String userId = (String) req.getAttribute("userId");
        userService.updatePassword(Integer.parseInt(userId),userPasswordUpdateDTO);
        writeData(resp, Result.success());
    }
}
